QuickOPC User's Guide and Reference
Examples - OPC Data Access - Read items of various data types
// Shows how different data types can be read, including rare types and arrays of values.

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess._EasyDAClient
{
    partial class ReadItem
    {
        // Instantiate the client object.
        static readonly EasyDAClient Client = new EasyDAClient();

        static void ReadAndDisplay(string itemId)
        {
            Console.WriteLine();
            Console.WriteLine("Reading \"{0}\"...", itemId);

            DAVtq vtq;
            try
            {
                vtq = Client.ReadItem("OPCLabs.KitServer.2", itemId);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }
            Console.WriteLine("Vtq: {0}", vtq);
        }

        public static void DataTypes()
        {
            ReadAndDisplay("Simulation.Register_EMPTY");
            ReadAndDisplay("Simulation.Register_NULL");
            ReadAndDisplay("Simulation.Register_DISPATCH");

            ReadAndDisplay("Simulation.ReadValue_I2");
            ReadAndDisplay("Simulation.ReadValue_I4");
            ReadAndDisplay("Simulation.ReadValue_R4");
            ReadAndDisplay("Simulation.ReadValue_R8");
            ReadAndDisplay("Simulation.ReadValue_CY");
            ReadAndDisplay("Simulation.ReadValue_DATE");
            ReadAndDisplay("Simulation.ReadValue_BSTR");
            ReadAndDisplay("Simulation.ReadValue_BOOL");
            ReadAndDisplay("Simulation.ReadValue_DECIMAL");
            ReadAndDisplay("Simulation.ReadValue_I1");
            ReadAndDisplay("Simulation.ReadValue_UI1");
            ReadAndDisplay("Simulation.ReadValue_UI2");
            ReadAndDisplay("Simulation.ReadValue_UI4");
            ReadAndDisplay("Simulation.ReadValue_INT");
            ReadAndDisplay("Simulation.ReadValue_UINT");

            ReadAndDisplay("Simulation.ReadValue_ArrayOfI2");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI4");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR4");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR8");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfCY");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfDATE");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBSTR");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBOOL");
            //ReadAndDisplay("Simulation.ReadValue_ArrayOfDECIMAL");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI1");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI1");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI2");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI4");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfINT");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUINT");
        }
    }
}
# Shows how different data types can be read, including rare types and arrays of values.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


def readAndDisplay(itemId):
    global client
    #
    print()
    print('Reading "', itemId, '"...', sep='')
    #
    try:
        vtq = IEasyDAClientExtension.ReadItem(client, ServerDescriptor('OPCLabs.KitServer.2'), DAItemDescriptor(itemId))
    except OpcException as opcException:
        print('*** Failure: ' + opcException.GetBaseException().Message)
        return
    print('Vtq: ', vtq, sep='')


# Instantiate the client object.
client = EasyDAClient()

#
readAndDisplay('Simulation.Register_EMPTY')
readAndDisplay('Simulation.Register_NULL')
readAndDisplay('Simulation.Register_DISPATCH')

readAndDisplay('Simulation.ReadValue_I2')
readAndDisplay('Simulation.ReadValue_I4')
readAndDisplay('Simulation.ReadValue_R4')
readAndDisplay('Simulation.ReadValue_R8')
readAndDisplay('Simulation.ReadValue_CY')
readAndDisplay('Simulation.ReadValue_DATE')
readAndDisplay('Simulation.ReadValue_BSTR')
readAndDisplay('Simulation.ReadValue_BOOL')
readAndDisplay('Simulation.ReadValue_DECIMAL')
readAndDisplay('Simulation.ReadValue_I1')
readAndDisplay('Simulation.ReadValue_UI1')
readAndDisplay('Simulation.ReadValue_UI2')
readAndDisplay('Simulation.ReadValue_UI4')
readAndDisplay('Simulation.ReadValue_INT')
readAndDisplay('Simulation.ReadValue_UINT')

readAndDisplay('Simulation.ReadValue_ArrayOfI2')
readAndDisplay('Simulation.ReadValue_ArrayOfI4')
readAndDisplay('Simulation.ReadValue_ArrayOfR4')
readAndDisplay('Simulation.ReadValue_ArrayOfR8')
readAndDisplay('Simulation.ReadValue_ArrayOfCY')
readAndDisplay('Simulation.ReadValue_ArrayOfDATE')
readAndDisplay('Simulation.ReadValue_ArrayOfBSTR')
readAndDisplay('Simulation.ReadValue_ArrayOfBOOL')
# readAndDisplay('Simulation.ReadValue_ArrayOfDECIMAL')
readAndDisplay('Simulation.ReadValue_ArrayOfI1')
readAndDisplay('Simulation.ReadValue_ArrayOfUI1')
readAndDisplay('Simulation.ReadValue_ArrayOfUI2')
readAndDisplay('Simulation.ReadValue_ArrayOfUI4')
readAndDisplay('Simulation.ReadValue_ArrayOfINT')
readAndDisplay('Simulation.ReadValue_ArrayOfUINT')

print()
print('Finished.')
' Shows how different data types can be read, including rare types and arrays of values.

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess._EasyDAClient
    Partial Friend Class ReadItem
        Private Shared ReadOnly DAClient As New EasyDAClient()

        Private Shared Sub ReadAndDisplay(itemId As String)
            Console.WriteLine()
            Console.WriteLine("Reading ""{0}""...", itemId)

            Dim vtq As DAVtq
            Try
                vtq = DAClient.ReadItem("OPCLabs.KitServer.2", itemId)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            Console.WriteLine("Vtq.ToString(): {0}", vtq.ToString())
        End Sub

        Shared Sub DataTypes()
            ReadAndDisplay("Simulation.Register_EMPTY")
            ReadAndDisplay("Simulation.Register_NULL")
            ReadAndDisplay("Simulation.Register_DISPATCH")

            ReadAndDisplay("Simulation.ReadValue_I2")
            ReadAndDisplay("Simulation.ReadValue_I4")
            ReadAndDisplay("Simulation.ReadValue_R4")
            ReadAndDisplay("Simulation.ReadValue_R8")
            ReadAndDisplay("Simulation.ReadValue_CY")
            ReadAndDisplay("Simulation.ReadValue_DATE")
            ReadAndDisplay("Simulation.ReadValue_BSTR")
            ReadAndDisplay("Simulation.ReadValue_BOOL")
            ReadAndDisplay("Simulation.ReadValue_DECIMAL")
            ReadAndDisplay("Simulation.ReadValue_I1")
            ReadAndDisplay("Simulation.ReadValue_UI1")
            ReadAndDisplay("Simulation.ReadValue_UI2")
            ReadAndDisplay("Simulation.ReadValue_UI4")
            ReadAndDisplay("Simulation.ReadValue_INT")
            ReadAndDisplay("Simulation.ReadValue_UINT")

            ReadAndDisplay("Simulation.ReadValue_ArrayOfI2")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI4")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR4")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfR8")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfCY")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfDATE")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBSTR")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfBOOL")
            'ReadAndDisplay("Simulation.ReadValue_ArrayOfDECIMAL");
            ReadAndDisplay("Simulation.ReadValue_ArrayOfI1")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI1")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI2")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUI4")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfINT")
            ReadAndDisplay("Simulation.ReadValue_ArrayOfUINT")
        End Sub
    End Class
End Namespace

 

See Also

Conceptual